<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise异步加载图片</title>
</head>
<body>
    
</body>
<script>
    function loadImage(src){
        return new Promise(function(resolve, reject){
            const img = new Image();
            img.src = src;
            img.onload = function(){
                resolve(img);
            };
            img.onerror = function(){
                reject(new Error('Could not load image at' + src));
            };
            document.body.appendChild(img);
        })
    }
    
    loadImage('https://www.baidu.com/img/bd_logo1.png')
       .then(image => {
           image.style.border = 'solid 6px red'
       })
</script>
</html>